1 | import os |
max1
2
3
4
5# max() 取最大值 min() sum()
list1 = [1,2,32,23,43,12,53]
print(max(list1)) # 53
print(min(list1)) # 1
print(sum(list1)) # 166
dir1
2
3# dir 查看某个对象下的方法 .不出来方法的时候可以使用
message = "hello"
print(dir(message))
sorted1
2
3
4
5
6# sorted 排序操作
print(sorted(list1,reverse=True)) # [1, 2, 12, 23, 32, 43, 53]
print(sorted("dasdqkdjwdekq")) # ['a', 'd', 'd', 'd', 'd', 'e', 'j', 'k', 'k', 'q', 'q', 's', 'w']
# 也能对集合进行排序
set1 = set(list1)
print(sorted(set1)) # [1, 2, 12, 23, 32, 43, 53]
chr1
2
3
4# chr() 打印数字对应的ascil
# ord() 打印字符对应的ascil数字
print(chr(97))
print(ord('a'))
round1
2# round() 保留几位小数
print(round(2.999,2)) # 会自动四舍五入
exec1
2
3
4
5
6
7
8
9
10
11
12
13
14# exec() 执行python代码(定义一个函数也能执行)
# eval() 执行python代码(只能执行简单的 a = 1)
execdemo = '''
def my():
print("大树先生的execdemo")
my()
'''
exec(execdemo) # 大树先生的execdemo
evaldemo = '''
1 + 1
'''
print(eval(evaldemo)) # 2
enumerate1
2
3
4
5
6
7
8# enumerate()枚举
stus = ["大一","大二","大三","大四"]
for i in range(len(stus)):
print(i,stus[i])
for i,s in enumerate(stus):
print(i,s)
for i,s in enumerate("大树先生"):
print(i,s)
zip1
2
3
4
5
6
7
8
9
10
11
12
13# zip()将多个list压缩到一起,当多个list数目不一样时,取最少的
name = ["大树","小花","王五","张三"]
age = [21,23,32,36]
stus = ["大一","大二","大三","大四"]
for l in zip(name,age,stus):
print(l)
# ('大树', 21, '大一')
# ···
for name,age,stus in zip(name,age,stus):
print(name,age,stus)
# print(map()) # 后续补充
# print(filter()) # 后续补充
map1
2
3
4
5
6
7
8
9# map生成函数生成器
DIRLIST = ["andriod", "iOS", "nginx", "tomcat", "mysql", "oracle", "loadrunner", "linux", "jmeter", "niujiaoshou"]
# 多个参数的时候没法使用,需要创建二维数组
res = (map(makdir,[str(i) for i in range(10000)]))
print(res)
for a in res:
print(a)
1 | # 生成器观察demo |
filter1
2
3
4
5
6
7# filter过滤器
def myFilter(num):
if num%2 == 0:
return True
# filter是过滤数据的函数,将过滤器返回结果为None或False的结果进行过滤
res = list(filter(myFilter,range(10)))
print(res)